package bsuir.magistrate.projects.gui.frames;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.filechooser.FileFilter;

import org.jfree.ui.RefineryUtilities;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import bsuir.magistrate.projects.gui.filters.ExtensionFileFilter;
import bsuir.magistrate.projects.gui.filters.util.FilterUtils;

@Component
public class MainFrame extends JFrame {

	@Autowired
	private FilterUtils filterUtils;

	private static final long serialVersionUID = -1179221610738752505L;

	private static final String TXT = "txt";
	private static final String BIN = "bin";
	private static final String TITLE = "Signal Analysis";

	public MainFrame() {
		super(TITLE);
		JMenu fileMenu = new JMenu("File");
		JMenuItem openItem = new JMenuItem("Open");
		JMenuItem parametersItem = new JMenuItem("Parameters");
		fileMenu.add(openItem);
		fileMenu.add(parametersItem);

		openItem.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				JFileChooser fileChooser = new JFileChooser();
				FileFilter filter = new ExtensionFileFilter(TXT + ", " + BIN,
						new String[] { TXT, BIN });
				fileChooser.setFileFilter(filter);
				filterUtils.initFileChooser(fileChooser);
			}
		});

		JMenuBar bar = new JMenuBar();
		setJMenuBar(bar);
		bar.add(fileMenu);

		getContentPane();
		setSize(800, 600);
		RefineryUtilities.centerFrameOnScreen(this);
		setVisible(true);
	}
}
